#!/bin/sh
# - eatmem_size
# - eatmem_duration
# - eatmem_nonuma
# - cpu_node_bind
# - mem_node_bind

. "$LKP_SRC/lib/reproduce-log.sh"
. "$LKP_SRC/lib/debug.sh"
. "$LKP_SRC/lib/numactl.sh"

USEMEM=/lkp/benchmarks/vm-scalability/usemem
[ -x $USEMEM ] ||
USEMEM=/lkp/benchmarks/eatmem/usemem

parse_numa_node_binding "$cpu_node_bind" "$mem_node_bind"

[ -z "$eatmem_size" ] && die "eatmem: eatmem_size required"
[ -z "$eatmem_duration" ] && eatmem_duration=$((3600*24))

for i in $(seq 0 $((nr_node-1))); do
	numa_bind=$(numa_node_binding "$i")
	log_cmd $numa_bind $USEMEM $((eatmem_size/nr_node)) --detach --sleep $eatmem_duration -p $TMP/eatmem_$i.pid --mlock --prefault
	cat $TMP/eatmem_$i.pid >> $TMP/pid-bg-proc-eatmem
	rm $TMP/eatmem_$i.pid
done
